import Vue from 'vue';
import VueRouter from 'vue-router';
import Home from '@/views/Home.vue';
import Shopping from '@/views/Shopping.vue';
import Classify from '@/views/Classify.vue';
import Search from '@/views/Search.vue';

VueRouter.prototype.back = false;
VueRouter.prototype.goBack = function goBack() {
    this.back = true;
    this.go(-1);
};

Vue.use(VueRouter);

const routes = [
    {
        path: '/home',
        name: 'Home',
        component: Home,
        children: [
            { // 分类
                path: 'classify',
                name: 'Classify',
                component: Classify,
            },
            { // 购物车
                path: 'shopping',
                name: 'Shopping',
                component: Shopping,
            },
        ],
    },
    {
        path: '/search',
        name: 'Search',
        component: Search,
    },
    {
        path: '*',
        redirect: '/home/classify',
    },
];

const router = new VueRouter({
    routes,
});

export default router;
